import axios from "axios";

//baseURL
// export const development = 'http://localhost:9010';
export const development = 'http://8.134.238.131:9010';

//axios
export const networkRequest = axios;


//基础配置
export const baseRequestConfig = {
    baseURL: development,
    url: '***',
    data: '***',
    method: 'post',
    timeout: 1000 * 30,
    headers: {
        'Content-Type': 'text/plain;charset=UTF-8',
    },
    transformRequest: [function (data, headers) {
        //1、map转对象
        const str = Object.fromEntries(data);
        //2、对象转字符串
        const str1 = JSON.stringify(str);
        return str1;
    }],
    transformResponse: [function (data) {
        // 对接收的 data 进行任意转换处理
        if (isJSON(data)) {
            const newData = JSON.parse(data);
            return newData;
        } else {
            //错误处理:非密文->转json对象
            const newData = JSON.parse(data);
            return newData;
        }
    }],
}

function isJSON(str) {
    try {
        JSON.parse(str);
        return true;
    } catch (e) {
        return false;
    }
}
